capture log close
clear all
set maxvar 10000
set more off
pause off
# delimit;

/* Figure B13 */

local data "" ;
local output "" ;


import excel "`data'/figB13.xlsx", sheet("Effect size table") firstrow ;

rename Effectsize Charges ;

drop if Paper == "" ; 

gen scale_transfer=1000 ;
gen scale=Transfersize/scale_transfer ;
egen paper=concat(Paper Intervention),p("_") ;
replace paper=Paper if Intervention=="" ;

split Charges, parse("(") ;
replace Charges1=subinstr(Charges1,"*","",.) ;
replace Charges2=subinstr(Charges2,")","",.) ;
destring Charges1, replace ;
destring Charges2, replace ;
rename (Charges1 Charges2)  (Charges_est Charges_se) ;
replace Charges_est=Charges_est/Periodyears ;
replace Charges_se=Charges_se/Periodyears ; 
replace Charges_est=Charges_est/scale ;
replace Charges_se=Charges_se/scale ; 
gen Charges_ll95=Charges_est-(1.96*Charges_se) ;
gen Charges_ul95=Charges_est+(1.96*Charges_se) ;


/* Criminal charges */

keep paper Charges_est Charges_ll95 Charges_ul95 ;
 
rename paper cite ;

gen paper="Deshpande2022" if cite=="Deshpande & Mueller-Smith (forthcoming)_SSI" ;
replace paper="Deshpande2022" if cite=="Deshpande & Mueller-Smith (forthcoming)_SSI male" ;
replace paper="Deshpande2022" if cite=="Deshpande & Mueller-Smith (forthcoming)_SSI female" ;
replace paper="Kling2005Exp" if cite=="Kling et al. 2005_Experimental male" ;
replace paper="Kling2005Exp" if cite=="Kling et al. 2005_Experimental female" ;
replace paper="Kling2005Exp" if cite=="Kling et al. 2005_Experimental" ;
replace paper="Kling2005S8" if cite=="Kling et al. 2005_Section 8 male" ;
replace paper="Kling2005S8" if cite=="Kling et al. 2005_Section 8 female" ;
replace paper="Kling2005S8" if cite=="Kling et al. 2005_Section 8" ;
replace paper="Garces2002" if cite=="Garces et al. 2002" ;
replace paper="Deming2009" if cite=="Deming 2009" ;

gen gp="all" if cite=="Deshpande & Mueller-Smith (forthcoming)_SSI" ;
replace gp="all" if cite=="Kling et al. 2005_Experimental" ;
replace gp="all" if cite=="Kling et al. 2005_Section 8"  ;
replace gp="all" if cite=="Garces et al. 2002" ;
replace gp="all" if cite=="Deming 2009" ;

replace gp="male"  if cite=="Deshpande & Mueller-Smith (forthcoming)_SSI male" ;
replace gp="male"  if cite=="Kling et al. 2005_Experimental male" ;
replace gp="male"  if cite=="Kling et al. 2005_Section 8 male" ;

replace gp="female" if cite=="Deshpande & Mueller-Smith (forthcoming)_SSI female" ;
replace gp="female" if cite=="Kling et al. 2005_Experimental female" ;
replace gp="female" if cite=="Kling et al. 2005_Section 8 female" ;

sort Charges_est ;
gen order = _n  ; 

local add_all     	= 0 ;
local add_male 		= .5 ;
local add_female    = -.5 ;

gen sort = . ; 

foreach gp in all male female { ;

	replace	sort = 10  + `add_`gp'' if paper == "Deshpande2022"  & gp == "`gp'" ;
	replace	sort = 8  + `add_`gp''  if paper == "Kling2005Exp" & gp == "`gp'" ;
	replace	sort = 6  + `add_`gp''  if paper == "Kling2005S8" & gp == "`gp'" ;
	replace	sort = 4  + `add_`gp''  if paper == "Garces2002" 	& gp == "`gp'" ;
	replace	sort = 2  + `add_`gp''  if paper == "Deming2009" & gp == "`gp'" ;	
} ;

twoway 

		(rcap Charges_ul95 Charges_ll95	sort 	if paper=="Deshpande2022" & gp=="all" , color(orange*.5) horizontal)
		(rcap Charges_ul95 Charges_ll95	sort 	if paper=="Kling2005Exp" & gp=="all" , color(gray*.5) horizontal)
		(rcap Charges_ul95 Charges_ll95	sort 	if paper=="Kling2005S8" & gp=="all" , color(gray*.5) horizontal)
		(rcap Charges_ul95 Charges_ll95 sort 	if paper == "Garces2002" & gp=="all" , color(gray*.5) horizontal)
		(rcap Charges_ul95 Charges_ll95	sort 	if paper == "Deming2009" & gp=="all" , color(gray*.5) horizontal)

		(rcap Charges_ul95 Charges_ll95	sort 	if paper=="Deshpande2022" & gp=="male" , color(blue*.5) horizontal)
		(rcap Charges_ul95 Charges_ll95	sort 	if paper=="Kling2005Exp" & gp=="male" , color(gray*.5) horizontal)
		(rcap Charges_ul95 Charges_ll95	sort 	if paper=="Kling2005S8" & gp=="male" , color(gray*.5) horizontal)
		
		(rcap Charges_ul95 Charges_ll95	sort 	if paper=="Deshpande2022" & gp=="female" , color(pink*.5) horizontal)
		(rcap Charges_ul95 Charges_ll95	sort 	if paper=="Kling2005Exp" & gp=="female" , color(gray*.5) horizontal)
		(rcap Charges_ul95 Charges_ll95	sort 	if paper=="Kling2005S8" & gp=="female" , color(gray*.5) horizontal)
					
					
		(pccapsym sort Charges_est sort Charges_est   	if paper == "Deshpande2022" & gp == "all", msize(medsmall) msymbol(o) color(orange) lwidth(medthin))
		(pccapsym sort Charges_est sort Charges_est   	if paper == "Kling2005Exp" & gp == "all", msize(medsmall) msymbol(o) color(gray) lwidth(medthin))
		(pccapsym sort Charges_est sort Charges_est   	if paper == "Kling2005S8" & gp == "all", msize(medsmall) msymbol(o) color(gray) lwidth(medthin))		
		(pccapsym sort Charges_est sort Charges_est 	if paper == "Garces2002" , msize(medsmall) color(gray) msymbol(o) lwidth(medthin))
		(pccapsym sort Charges_est sort Charges_est 	if paper == "Deming2009" , msize(medsmall) color(gray) msymbol(o) lwidth(medthin))
		
		(pccapsym sort Charges_est sort Charges_est 	if paper == "Deshpande2022" & gp == "male", msize(medsmall) msymbol(Oh) color(blue) lwidth(medthick))
		(pccapsym sort Charges_est sort Charges_est 	if paper == "Kling2005Exp" & gp == "male", msize(medsmall) msymbol(Oh) color(gray) lwidth(medthick))
		(pccapsym sort Charges_est sort Charges_est 	if paper == "Kling2005S8" & gp == "male", msize(medsmall) msymbol(Oh) color(gray) lwidth(medthick))
		
		(pccapsym sort Charges_est sort Charges_est 	if paper == "Deshpande2022" & gp == "female", msize(medium) msymbol(X) color(pink) lwidth(medthick))
		(pccapsym sort Charges_est sort Charges_est 	if paper == "Kling2005Exp" & gp == "female", msize(medium) msymbol(X) color(gray) lwidth(medthick))
		(pccapsym sort Charges_est sort Charges_est 	if paper == "Kling2005S8" & gp == "female", msize(medium) msymbol(X) color(gray) lwidth(medthick))
			
	,  
		legend(off) 
		text(9.26 -0.016 "Female", color(pink) size(vsmall)) 
		text(10.265 -0.0055 "Male", color(blue) size(vsmall)) 
		text(7.26 -0.004 "Female", color(gray) size(vsmall)) 
		text(8.26 0.004 "Male", color(gray) size(vsmall)) 			
		text(5.26 -0.002 "Female", color(gray) size(vsmall)) 
		text(6.26 0.003 "Male", color(gray) size(vsmall)) 		
		title("Estimates of effects on arrests/charges", size(medsmall))
		xtitle("Effect size per $1000 transfer", size(medsmall))
		ytitle("")
		graphregion(color(white))
		bgcolor(white)
		xlabel(-.03(.01).03) 
		ysc(r(1 11))
		ylabel(
		   8 "Kling et al. (2005) - MTO" 6 "Kling et al. (2005) - Section 8" 4 "Garces et al. (2002) - Head Start" 2 "Deming (2009) - Head Start" , 
		   angle(0) notick labsize(vsmall) axis(1) ) 
		ylabel(
		   10 "Deshpande & Mueller-Smith (2022)" , add custom labcolor(orange) 
		   angle(0) notick labsize(vsmall) axis(1) ) 		   
		ylabel(,nogrid angle(0) axis(1))
		plotregion(margin(0 0 2 2))  
		xline(0, lcolor(gray) lpattern(dot))
		;
		
		graph export "`output'/figB13.png", as(png) width(1000) height(750) replace ;

